<?php

/*
    String test case
        Template author:        Alfredo Mungo
        Test author:            Alfredo Mungo
*/

define("TEST_TITLE", "String class");

include 'test_suit.php';
include '../modules/String.php';

function test1()
{
    $str = new String("Goofy has a brand new CAR.");
    
    test_report_add_result("length()", $str->length() == strlen($str->value()));
    test_report_add_result("value()", $str->value() == "Goofy has a brand new CAR.");
    
    $str->append(" Mickey does not.");
    test_report_add_result("append()", $str->value() == "Goofy has a brand new CAR. Mickey does not.");
    
    test_report_add_result("toUpper()", $str->toUpper() == "GOOFY HAS A BRAND NEW CAR. MICKEY DOES NOT.");
    test_report_add_result("toLower()", $str->toLower() == "goofy has a brand new car. mickey does not.");
    test_report_add_result("toProper()", $str->toProper() == "Goofy has a brand new car. mickey does not.");
    
    test_report_add_result("getChar()", $str->getChar(0) === 'G' && $str->getChar(4) === 'y');
    $str->setChar(0, 'M');
    test_report_add_result("setChar()", $str->value() == "Moofy has a brand new CAR. Mickey does not.");
    
    test_report_add_result("find()", $str->find('Mickey') == 27 && $str->find('Moofy', 1) === false);
    $str->replace('a', 'A', 3);
    $str->replace('o', '0');
    test_report_add_result("replace()", $str->value() == 'M00fy hAs A brAnd new CAR. Mickey d0es n0t.');
    
    $arr = $str->explode('.');
    test_report_add_result("explode(delim)", $arr[0] == 'M00fy hAs A brAnd new CAR' && $arr[1] == ' Mickey d0es n0t' && $arr[2] == '');
    
    $arr = $str->explode('.', 2);
    test_report_add_result("explode(delim, count)", $arr[0] == 'M00fy hAs A brAnd new CAR' && $arr[1] == ' Mickey d0es n0t.', print_r($arr, true));
    
    $str = new String("  \t\t\t\t ciccio bello... a    ");
    $str->trim();
    test_report_add_result("trim()", $str->value() == 'ciccio bello... a');
    $str->trim('ciaO');
    test_report_add_result("trim(trim_chars)", $str->value() == 'o bello... ');
}

test_register('test1', "Methods test");
test_run();

include 'test_template.php';

?>